export const baseURL = 'http://61.182.254.18:9150';//线上接口地址，图片拼接地址
export function request(params){
  let dataObj = params.data;
  let userInfo = wx.getStorageSync('userInfo')
  let headerObj = {
    'content-type':'application/json',
    "Authorization" : `Bearer ${userInfo.token}`
  }
  return new Promise((resolve,reject)=>{
    wx.request({
      url: baseURL + params.url,
      method: params.method || "GET",
      data: dataObj,
      header:headerObj,
      success:res =>{
        //console.log(res);
        if(res.data.code == 200){
          resolve(res.data)
          return;
        }else if(res.data.code==401){
          wx.showModal({
            title: '系统提示',
            content: '登录已过期，重新登陆',
            showCancel: false,
            complete: (res) => {
              if (res.cancel) {
                wx.removeStorageSync('userInfo')
                wx.reLaunch({
                  url: '../pages/login/login',
                })
              }
            }
          })
        }else{
          reject(res)
        }
      },
      fail:err =>{
        reject(err)
      }
    })
  })
}
